package com.atguigu.webadmin.controller.apartment;


import com.atguigu.common.result.Result;
import com.atguigu.model.pojo.LeaseTerm;
import com.atguigu.webadmin.service.LeaseTermService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "租期管理")
@RequestMapping("/admin/term")
@RestController
@CrossOrigin
public class LeaseTermController {

    @Autowired
    private LeaseTermService leaseTermService;

    @GetMapping("list")
    @Operation(summary = "查询全部租期列表")
    public Result<List<LeaseTerm>> listLeaseTerm() {
        List<LeaseTerm> leaseTerms = leaseTermService.listLeaseTerm();
        return Result.ok(leaseTerms);
    }

    @PostMapping("saveOrUpdate")
    @Parameters({
            @Parameter(name = "leaseTerm",description = "租期信息更新对象",in = ParameterIn.DEFAULT)
    })
    @Operation(summary = "保存或更新租期信息")
    public Result<Boolean> saveOrUpdate(@RequestBody LeaseTerm leaseTerm) {
        //保存或更新租期信息
        boolean b = leaseTermService.saveOrUpdate(leaseTerm);
        return Result.ok(b);
    }

    @DeleteMapping("deleteById")
    @Parameters({
            @Parameter(name = "id",description = "租期id",in = ParameterIn.DEFAULT)
    })
    @Operation(summary = "根据ID删除租期")
    public Result<Boolean> deleteLeaseTermById(@RequestParam Long id) {
        //根据id逻辑删除租期
        boolean b = leaseTermService.removeById(id);
        return Result.ok(b);
    }
}
